package com.team7.happycommunity.parkservice.service.impl;

import com.team7.happycommunity.parkservice.dao.OwnerParkingApplyMapper;
import com.team7.happycommunity.parkservice.dao.ParkingInfoMapper;
import com.team7.happycommunity.parkservice.dao.PersonUserMapper;
import com.team7.happycommunity.parkservice.dto.AddParkingApply;
import com.team7.happycommunity.parkservice.pojo.OwnerParkingApply;
import com.team7.happycommunity.parkservice.pojo.ParkingInfo;
import com.team7.happycommunity.parkservice.pojo.PersonUser;
import com.team7.happycommunity.parkservice.service.ParkingApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ParkingApplyServiceImpl implements ParkingApplyService {

    @Autowired
    OwnerParkingApplyMapper ownerParkingApplyMapper;

    @Autowired
    PersonUserMapper personUserMapper;

    @Override
    public int add(AddParkingApply addParkingApply) {
        // 获取personUser的用户id
        PersonUser personUser = personUserMapper.selectByUsername(addParkingApply.getUserName());
        // 存入
        OwnerParkingApply ownerParkingApply = new OwnerParkingApply();
        ownerParkingApply.setOwnerId(personUser.getId());
        ownerParkingApply.setBeginTime(addParkingApply.getBeginTime());
        ownerParkingApply.setEndTime(addParkingApply.getEndTime());
        ownerParkingApply.setCommunityId(addParkingApply.getAreaid());
        ownerParkingApply.setCostPerDay(addParkingApply.getCostPerDay());
        ownerParkingApply.setParkingCode(addParkingApply.getParkingNumber());
        ownerParkingApply.setParkingInfo(addParkingApply.getParkingInfos());
        ownerParkingApply.setStatus(0);// 未审核状态
        return ownerParkingApplyMapper.insertSelective(ownerParkingApply);
    }
}
